package com.woniu.adopt_web.service;

import com.woniu.adopt_web.entity.Message;
import com.woniu.adopt_web.entity.Pet;
import com.woniu.adopt_web.mapper.UserMapper;
import com.woniu.adopt_web.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    UserMapper userMapper;

//    @Autowired
//    RedisTemplate<String, Object> redisTemplate;

//    @Cacheable(value = "user",key="#root.method.name")
    public UserVo login(String username, String password) {
            UserVo userByName = userMapper.selectUserByName(username);
            if (!userByName.getPassword().equals(password)) {
                return null;
            } else {
              return userByName;
            }
    }

    public UserVo findUserByName(String username) {
        return userMapper.selectUserByName(username);
    }

    public int addUserByRegister(UserVo userVo) {
        return userMapper.insertUserByRegister(userVo);
    }

    public int modifyUserByUid(UserVo userVo) {
        return userMapper.updateByPrimaryKey(userVo);
    }

    public List<Pet> findPetColListByUid(Integer uid) {
        return userMapper.selectPetColList(uid);
    }

    public void updateApply(Integer uid, String message,Integer status) {
        userMapper.updateApply(uid, message,status);
    }

    public void delApply(Integer uid) {
        userMapper.delApply(uid);
    }

    public Integer getMessageStatus(Integer uid) {
        return userMapper.selectMessageStatusByUid(uid);
    }

    public void insertApply(Integer uid, String message) {
        userMapper.insertApply(uid,message);
    }

    public String queryMessageByUid(Integer uid) {
        return userMapper.queryMessageByUid(uid);
    }

    public List<Message> findMessageListByUid(Integer id) {
        return userMapper.selectMessageListByUid(id);
    }

    public int modifyMessageByUid(int uid) {
        return userMapper.updateMssageByUid(uid);
    }

    public int findUnRead(Integer id) {
        return userMapper.selectUnRead(id);
    }
}
